short int valA0;
short int tempx;

void setup() {
  Serial.begin(9600);
}

void loop() {
  valA0 = analogRead(A0);

  if(valA0 >= 610 && valA0 <= 680)
    tempx = convert(valA0, 680, 610, -20, 0);
  else if(valA0 >= 550 && valA0 <= 610)
    tempx = convert(valA0, 610, 550, 0, 20); 
  else if(valA0 >= 450 && valA0 <= 550)
    tempx = convert(valA0, 550, 450, 20, 40);
  else if(valA0 >= 320 && valA0 <= 450)
    tempx = convert(valA0, 450, 320, 40, 60);
  else if(valA0 >= 220 && valA0 <= 320)
    tempx = convert(valA0, 320, 220, 60, 80);
  else if(valA0 >= 150 && valA0 <= 220)
    tempx = convert(valA0, 220, 150, 80, 100);
    
   Serial.println( valA0 );
   Serial.println( tempx ); 
}

short int convert(short int ax, short int a0,short int a1, short int temp0,short int temp1){
   short int tempx;
   tempx = temp0+(ax-a0)*(temp1-temp0)/(a1-a0);
   return tempx;
}

